﻿using System;
using System.Diagnostics;
using Azukit.ViewModel;

namespace Hibiku.ViewModels
{
    public class LogViewModel : ViewModelBase
    {
        public string Text
        {
            get;
            private set;
        }

        public bool IsError
        {
            get;
            private set;
        }

        public LogViewModel()
        {
            IsError = false;
            Text = "";
        }

        public void Update(bool isError, string format, params object[] args)
        {
            Text = DateTime.Now.ToString("HH:mm:ss") + ": " + string.Format(format, args);
            IsError = isError;

            FirePropertyChanged(() => IsError);
            FirePropertyChanged(() => Text);
        }

        public void Error(string format, params object[] args)
        {
            Trace.TraceError(string.Format(format, args));

            Update(true, format, args);
        }

        public void Info(string format, params object[] args)
        {
            Update(false, format, args);
        }

        public override string ToString()
        {
            return Text;
        }
    }
}
